package com.zhkc.wisdom.common.base.util;


import com.zhkc.wisdom.common.base.context.SecurityContextHolder;
import com.zhkc.wisdom.common.base.model.LoginContextInfo;

import java.util.Optional;


/**
 * 获取登录用户信息
 */
public class SecurityUtils {
    /**
     * 获取当前账户
     *
     * @return
     */
    public static LoginContextInfo getAccount() {
        return SecurityContextHolder.getAuthObject();
    }

    /**
     * 获取账号Id.
     *
     * @return
     */
    public static Long getAccountId() {
        return Optional.ofNullable(getAccount()).map(LoginContextInfo::getAccountId)
                .orElse(null);
    }


    /**
     * 获取租户Id
     *
     * @return
     */
    public static Long getTenantId() {
        return Optional.ofNullable(getAccount()).map(LoginContextInfo::getTenantId)
                .orElse(null);
    }

}